#include "lowpass_filter.h"

void lowpass_filter_init(lowpass_filter_type* lowpass_handler)
{
  double cal_temp;

  cal_temp = (double) lowpass_handler->bandwidth / lowpass_handler->sample_freq;

  lowpass_handler->coef1 = 1 / (1 + cal_temp);
  lowpass_handler->coef2 = cal_temp / (1 + cal_temp);
}

/**
  * @brief  lowpass filter function
  * @param  lowpass_handler: lowpass filter related variables
  * @param  input_handler: raw data
  * @retval filtered data
  */
float lowpass_filtering(lowpass_filter_type* lowpass_handler, float input_handler)
{
  lowpass_handler->output_temp = lowpass_handler->coef1 * lowpass_handler->output_temp;
  lowpass_handler->output_temp = lowpass_handler->output_temp + lowpass_handler->coef2 * input_handler;

  return lowpass_handler->output_temp;
}